PROJECT=libpam_json
CC=gcc
#there is bug with -O
CFLAGS=
SO_SOURCES=pam_json.c
C_SOURCES=ha_login.c
 
make:
	$(CC) $(CFLAGS) -fPIC -c mmm.c
	$(CC) $(CFLAGS) -fPIC -c sha512.c
	$(CC) $(CFLAGS) -fPIC -c base64.c
	$(CC) $(CFLAGS) -fPIC  -c read_json_db.c
	$(CC) $(CFLAGS) mmm.o sha512.o read_json_db.o -fPIC -shared -ldl \
	 -ljson $(SO_SOURCES) -o $(PROJECT).so
	#$(CC) $(CFALGS) read_json_db.o -ljson-c test1.c -o test1

test:
	rm -f read_json_db.o
	rm -f base64.o
	rm -f sha512.o
	$(CC) $(CFLAGS) -c mmm.c
	$(CC) $(CFLAGS) -c read_json_db.c
	$(CC) $(CFLAGS) -c sha512.c
	$(CC) $(CFLAGS) -c base64.c
	$(CC) $(CFLAGS) mmm.o read_json_db.o -ljson-c test1.c -o test1
	$(CC) $(CFLAGS) mmm.o read_json_db.o -ljson-c sha512.o base64.o test2.c -o test2

login:
	$(CC) $(CFLAGS) -c mmm.c
	$(CC) $(CFLAGS) -c base64.c
	$(CC) $(CFLAGS) -c sha512.c 
	$(CC) $(CFLAGS) -c read_json_db.c
	$(CC) $(CFLAGS) mmm.o read_json_db.o base64.o sha512.o -ljson-c -lpam ha_login.c -o ha_login 

leak:
	valgrind --leak-check=full --track-origins=yes --log-file=log.txt ./ha_login

debug_set_flag:
	$(CFLAGS)=-g3

debug: debug_set_flag make
	echo "debug"

clean:
	rm -rf *.o
	rm -f ha_login
	rm -f test1
	rm -f test2
	rm -f libpam_json.so

